<?php
// 上传文件保存路径
$uploadDir = 'uploads/';

// 生成唯一ID
$uniqueId = substr(md5(uniqid()), 0, 8);

// 获取文件扩展名
$fileExtension = pathinfo($_FILES['fileToUpload']['name'], PATHINFO_EXTENSION);

// 新的文件名为唯一ID + 原文件名
$newFileName = $uniqueId . '_' . $_FILES['fileToUpload']['name'];
$uploadFile = $uploadDir . $newFileName;

// 处理文件上传
if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $uploadFile)) {
    echo json_encode(['status' => 'success', 'fileName' => $newFileName]);
} else {
    echo json_encode(['status' => 'error']);
}
?>
